package com.yxhl.zoume.core.officialcar.fragment;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MyLocationStyle;
import com.yxhl.protobuf.BizOrderResponse;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.custom.CheckBoxLayout;
import com.yxhl.zoume.core.specialcar.model.SpecialCarRideStatus;
import com.yxhl.zoume.core.officialcar.presenter.OfficialCarScheduleMapPresenter;
import com.yxhl.zoume.core.officialcar.activity.OfficialCarScheduleActivity;
import com.yxhl.zoume.core.specialcar.model.DialTelephoneEvent;
import com.yxhl.zoume.core.officialcar.view.OfficialCarScheduleMapView;
import com.yxhl.zoume.core.func.appraisal.model.AppraisalDriverInfo;
import com.yxhl.zoume.core.func.map.ui.fragment.BaseMapFragment;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CommentOnDriverView;
import com.yxhl.zoume.di.component.car.DaggerOfficialCarComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.domain.interactor.ZMEventSubscriber;
import com.yxhl.zoume.utils.DeviceUtils;
import com.yxhl.zoume.utils.DiskCacheUtils;
import com.yxhl.zoume.utils.LOG;
import com.yxhl.zoume.utils.PopupWindowUtils;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.ZMDialog;
import com.yxhl.zoume.utils.permission.PermissionHelper;

import java.util.LinkedList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;
import rx.functions.Action1;

/**
 * created by sugarya 16/08/27
 * 公务车行程地图页
 */
public class OfficialCarScheduleMapFragment extends BaseMapFragment implements OfficialCarScheduleMapView, CommentOnDriverView {

    public static final int PICK_UP_MOVE_DURATION = 600;
    public static final int DRIVER_INFO_MOVE_DURATION = 400;
    /**
     * 第二次地图移动的边距
     */
    public static final int MOVE_PADDING = 20;
    private static final String TAG = "OfficialCarScheduleMapFragment";
    private static final int SECOND_ANIMATE_MOVE_DELAY = 1000;
    private static final float MAP_ZOOM_LEVEL = 13;
    @BindView(R.id.frame_fragment_special_car_schedule_root)
    FrameLayout mRootFrame;

    @BindView(R.id.rl_special_car_service_header_container)
    RelativeLayout mHeaderContainerRl;

    //接驾信息栏
    @BindView(R.id.rl_special_car_service_schedule_hint)
    RelativeLayout mScheduleBarRl;
    @BindView(R.id.tv_special_car_service_schedule_title)
    TextView mScheduleTitleTv;
    @BindView(R.id.iv_special_car_service_schedule_icon)
    ImageView mScheduleIconIv;

    //司机信息栏
    @BindView(R.id.rl_special_car_service_driver_info_container)
    RelativeLayout mDriverInfoRl;
    @BindView(R.id.tv_special_car_service_driver_info_title)
    TextView mDriverInfoTitleTv;
    @BindView(R.id.cbl_special_car_service_driver_info_comment)
    CheckBoxLayout mCommentCheckBoxLayout;
    @BindView(R.id.iv_special_car_service_driver_info_phone)
    ImageView mDriverInfoPhoneIv;

    @BindView(R.id.frame_special_car_service_location)
    LinearLayout mLocationFrame;

    //行程统计时间和公里栏
    @BindView(R.id.ll_official_car_bottom_schedule_time_distance_bar)
    LinearLayout mScheduleTimeDistanceBar;

    @BindView(R.id.tv_official_car_schedule_time)
    TextView mScheduleTimeTv;

    @BindView(R.id.tv_official_car_schedule_distance)
    TextView mScheduleDistance;

    //arguments
    @Inject
    OfficialCarScheduleMapPresenter mOfficialCarScheduleMapPresenter;

    private String mOrderId;

    private PopupWindow mPhonePopupWindow;

    private String mDriverMobile;

    private AMap aMap;
    /**
     * 出发点经纬度
     */
    private List<com.yxhl.protobuf.Location> mDepartLatLngList;

    /**
     * 目的地经纬度
     */
    private List<com.yxhl.protobuf.Location> mArrivalLatLngList;

    /**
     * 等待接驾 小车图标帧动画
     */
    private AnimationDrawable mAnimationDrawable;


    public OfficialCarScheduleMapFragment() {
        // Required empty public constructor
    }

    public static OfficialCarScheduleMapFragment newInstance(String officialCarOrderId) {

        OfficialCarScheduleMapFragment fragment = new OfficialCarScheduleMapFragment();
        Bundle args = new Bundle();
        args.putString(UIConstants.Car.ARGUMENT_KEY_OFFICIAL_CAR_SCHEDULE_MAP, officialCarOrderId);
        fragment.setArguments(args);
        return fragment;
    }

    public void onRxBusEvent() {
        getSubscription().add(toSubscription(DialTelephoneEvent.class,
                new Action1<DialTelephoneEvent>() {
                    @Override
                    public void call(DialTelephoneEvent dialTelephoneEvent) {
                        if (dialTelephoneEvent.getFromDirection() == DialTelephoneEvent.FROM_SCHEDULE_DRIVER_MOBILE) {
                            if (!TextUtils.isEmpty(mDriverMobile)) {
                                DeviceUtils.dialTelPhone(mActivity, mDriverMobile);
                            }
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));
    }

    private void parseArguments() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mOrderId = arguments.getString(UIConstants.Car.ARGUMENT_KEY_OFFICIAL_CAR_SCHEDULE_MAP, "");
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        parseArguments();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        this.aMap = mMapView.getMap();
        mOfficialCarScheduleMapPresenter.attachView(this);
        mOfficialCarScheduleMapPresenter.init(aMap);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBaseStartMoveToLocation = true;
        mOfficialCarScheduleMapPresenter.startPolling(mActivity, mOrderId);
    }

    @Override
    public void onResume() {
        super.onResume();
        mOfficialCarScheduleMapPresenter.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mOfficialCarScheduleMapPresenter.onPause();
    }

    @Override
    public void onDestroyView() {
        closePhonePopupWindow();
        if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
            mAnimationDrawable.stop();
        }
        if (mOfficialCarScheduleMapPresenter != null) {
            mOfficialCarScheduleMapPresenter.unbindTcpService(mActivity);
        }
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        getSubscription().unsubscribe();
        mOfficialCarScheduleMapPresenter.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            setupToolBar();
        }
    }

    @OnClick(R.id.frame_special_car_service_location)
    public void onLocationIconClick(View view) {
        Location location = mMapView.getMap().getMyLocation();
        if (location != null) {
            animateMoveTo(new LatLng(location.getLatitude(), location.getLongitude()), MAP_ZOOM_LEVEL);
        }
    }

    @OnClick(R.id.iv_special_car_service_driver_info_phone)
    public void onDriverInfoPhoneIconClick(View view) {
        showPhonePopupWindow();
    }


    private void showPhonePopupWindow() {
        if (mPhonePopupWindow != null) {
            setWindowBackgroundAlpha(0.5f);
            mPhonePopupWindow.showAtLocation(mRootFrame, Gravity.BOTTOM, 0, 0);
        } else {
            initializePhonePopupWindow(mDriverMobile);
        }
    }

    /**
     * 设置窗口透明度
     *
     * @param bgAlpha
     */
    private void setWindowBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams attributes = mActivity.getWindow().getAttributes();
        attributes.alpha = bgAlpha;
        mActivity.getWindow().setAttributes(attributes);
    }

    /**
     * 关闭电话弹窗
     */
    public void closePhonePopupWindow() {
        if (mPhonePopupWindow != null) {
            if (mPhonePopupWindow.isShowing()) {
                mPhonePopupWindow.dismiss();
            }
        }
    }

    private void initializePhonePopupWindow(String driverMobile) {
        onRxBusEvent();

        View contentView = getActivity().getLayoutInflater().inflate(R.layout.popup_special_car_schedule_phone, null);
        TextView mPopupTitleTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_title);
        TextView mPopupContentTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_content);
        TextView mPopupCancelTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_cancel);
        TextView mPopupDialTv = (TextView) contentView.findViewById(R.id.tv_popup_special_car_schedule_dial);

        if (driverMobile != null) {
            mDriverMobile = driverMobile;
            if (!TextUtils.isEmpty(driverMobile)) {
                mPopupTitleTv.setText(driverMobile);
            }
        }

        mPopupContentTv.setText(getString(R.string.special_car_popup_dial_content));
        mPopupCancelTv.setText(getString(R.string.special_car_dialog_cancel));
        mPopupDialTv.setText(getString(R.string.special_car_popup_dial_confirm));
        mPopupDialTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (PermissionHelper.checkPhonePermission(mActivity)) {
                    DeviceUtils.dialTelPhone(mActivity, mDriverMobile);
                } else {
                    PermissionHelper.takeCallPhonePermission(mActivity, PermissionHelper.REQUEST_CODE_CALL_SPECIAL_CAR_DRIVER);
                }
            }
        });
        mPopupCancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closePhonePopupWindow();
            }
        });

        mPhonePopupWindow = PopupWindowUtils.getSchedulePhonePopupWindow(contentView);
        mPhonePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setWindowBackgroundAlpha(1f);
            }
        });
    }


    /**
     * 司机信息栏进入动画
     */
    private void startEnterAnimatorForDriverInfo(final boolean isRunPickUpEnterAnimator) {
        int height = mDriverInfoRl.getHeight();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mHeaderContainerRl, "translationY", 0, height);
        translateAnimator.setInterpolator(new DecelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mDriverInfoRl, "alpha", 0, 1f);

        AnimatorSet enterAnimatorSet = new AnimatorSet();
        enterAnimatorSet.setDuration(DRIVER_INFO_MOVE_DURATION);
        enterAnimatorSet.playTogether(translateAnimator, alphaAnimator);
        enterAnimatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                if (isRunPickUpEnterAnimator) {
                    startEnterAnimatorForScheduleBar();
                }
            }
        });

        enterAnimatorSet.start();
    }


    /**
     * 获取 动画移动所需的距离
     *
     * @return
     */
    private int getDeltaTranslationX() {
        int screenWidth = DeviceUtils.getScreenWidth(getContext());
        int pickUpRlWidth = mScheduleBarRl.getWidth();
        int ret = (screenWidth - pickUpRlWidth) / 2 + pickUpRlWidth;
        return ret;
    }


    @Override
    protected Marker getLocationMarker(AMap aMap, LatLng latLng) {
//        if (mLastLocationMarker != null) {
//            mLastLocationMarker.remove();
//        }
//
//        MarkerOptions markerOptions = new MarkerOptions();
//        Bitmap iconBmp = BitmapFactory.decodeResource(getResources(), R.drawable.icon_user_location);
//        markerOptions
//                .setFlat(true)
//                .icon(BitmapDescriptorFactory.fromBitmap(iconBmp))
//                .position(latLng)
//                .anchor(0.5f, 0.5f);
//
//        mLastLocationMarker = aMap.addMarker(markerOptions);

        return null;
    }

    @Override
    protected boolean setUpLocationStyle(AMap aMap) {
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.icon_user_location));
        myLocationStyle.radiusFillColor(Color.TRANSPARENT);
        myLocationStyle.strokeColor(Color.TRANSPARENT);
        aMap.setMyLocationStyle(myLocationStyle);

        return true;
    }

    @Override
    protected float getLocationMapZoomLevel() {
        return MAP_ZOOM_LEVEL;
    }

    @Override
    protected void secondAnimateMove() {
        final List<LatLng> latLngList = new LinkedList<>();
        if (mDepartLatLngList != null && mDepartLatLngList.size() > 0) {
            for (com.yxhl.protobuf.Location location : mDepartLatLngList) {
                String lat = location.getLat();
                String lng = location.getLng();
                LOG.e(TAG, "mDepartLatLngList lat=" + lat + "lng=" + lng);
                double latDouble;
                double lngDouble;
                try {
                    latDouble = Double.parseDouble(lat);
                    lngDouble = Double.parseDouble(lng);
                } catch (Exception e) {
                    e.printStackTrace();
                    latDouble = 0;
                    lngDouble = 0;
                }
                latLngList.add(new LatLng(latDouble, lngDouble));
            }
        }
        if (mArrivalLatLngList != null && mArrivalLatLngList.size() > 0) {
            for (com.yxhl.protobuf.Location location : mArrivalLatLngList) {
                String lat = location.getLat();
                String lng = location.getLng();
                LOG.e(TAG, "mArrivalLatLngList lat=" + lat + "lng=" + lng);
                double latDouble;
                double lngDouble;
                try {
                    latDouble = Double.parseDouble(lat);
                    lngDouble = Double.parseDouble(lng);
                } catch (Exception e) {
                    e.printStackTrace();
                    latDouble = 0;
                    lngDouble = 0;
                }
                latLngList.add(new LatLng(latDouble, lngDouble));
            }
        }

        mRootFrame.postDelayed(new Runnable() {
            @Override
            public void run() {
                animateMoveTo(latLngList, MOVE_PADDING);
            }
        }, SECOND_ANIMATE_MOVE_DELAY);
    }


    @Override
    public void renderDataOnFailure(String resultMessage) {
        PromptUtils.showShort(getContext(), resultMessage);
    }

    @Override
    public void renderDataOnSuccess(BizOrderResponse response) {
        OrderBizType orderBizType = response.getOrderBizType();
        switch (orderBizType) {
            case OFFICIAL_BUS_WAY:
                mDepartLatLngList = response.getLnglatsList();
                mArrivalLatLngList = response.getElnglatsList();
                mOfficialCarScheduleMapPresenter.refreshOfficialCarMileageMarkersInMap(
                        mMapView.getMap(),
                        mDepartLatLngList,
                        mArrivalLatLngList
                );
                break;

            case OFFICIAL_BUS_TIME:
                mDepartLatLngList = response.getLnglatsList();
                mArrivalLatLngList = response.getElnglatsList();
                mOfficialCarScheduleMapPresenter.refreshOfficialCarTimingMarkersInMap(
                        mMapView.getMap(),
                        mDepartLatLngList
                );
                break;
        }

    }

    /**
     * 订单信息栏进入动画
     */
    @Override
    public void startEnterAnimatorForScheduleBar() {
        //开启小车帧动画
        mAnimationDrawable = (AnimationDrawable) mScheduleIconIv.getDrawable();
        mAnimationDrawable.start();

        int deltaTranslationX = getDeltaTranslationX();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "translationX", 0, deltaTranslationX);
        translateAnimator.setInterpolator(new DecelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "alpha", 0.3f, 1);
        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "scaleX", 0.3f, 1);

        AnimatorSet enterAnimatorSet = new AnimatorSet();
        enterAnimatorSet.setDuration(PICK_UP_MOVE_DURATION);
        enterAnimatorSet.playTogether(translateAnimator, alphaAnimator, scaleXAnimator);

        enterAnimatorSet.start();
    }

    /**
     * 司机信息栏退出动画
     */
    @Override
    public void startExitAnimatorForDriverInfo() {
        int height = mDriverInfoRl.getHeight();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mHeaderContainerRl, "translationY", height, 0);
        translateAnimator.setInterpolator(new AccelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mDriverInfoRl, "alpha", 1f, 0.6f);

        AnimatorSet exitAnimatorSet = new AnimatorSet();
        exitAnimatorSet.setDuration(DRIVER_INFO_MOVE_DURATION);
        exitAnimatorSet.playTogether(translateAnimator, alphaAnimator);

        exitAnimatorSet.start();
    }

    @Override
    public void setupHeaderStatus(String title, String operation) {
        ((OfficialCarScheduleActivity) mActivity).setToolbar(title, operation);
    }

    @Override
    public void setupTitleStatus(String title) {
        ((OfficialCarScheduleActivity) mActivity).setToolbar(title, "");
    }

    @Override
    public void setupScheduleBarStatus(String message, boolean iconVisibility) {
        if (iconVisibility) {
            mScheduleIconIv.setVisibility(View.VISIBLE);
        } else {
            mScheduleIconIv.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(message)) {
            mScheduleTitleTv.setText(message);
        }
    }

    /**
     * @param driverInfo 司机姓名和车牌号
     * @param judgePoint
     */
    @Override
    public void setupDriverInfoStatus(String driverInfo, int judgePoint, boolean isPhoneIconVisible, String mobile) {
        if (!TextUtils.isEmpty(driverInfo)) {
            mDriverInfoTitleTv.setVisibility(View.VISIBLE);
            if (isPhoneIconVisible) {
                mDriverInfoPhoneIv.setVisibility(View.VISIBLE);
            } else {
                mDriverInfoPhoneIv.setVisibility(View.INVISIBLE);
            }

            mDriverInfoTitleTv.setText(driverInfo);
            mCommentCheckBoxLayout.setCheckedCount(judgePoint);
        } else {
            mDriverInfoTitleTv.setVisibility(View.INVISIBLE);
            mDriverInfoPhoneIv.setVisibility(View.INVISIBLE);
        }
        mDriverMobile = mobile;
    }


    /**
     * 订单信息栏退出动画
     *
     * @param
     */
    @Override
    public void startExitAnimatorForScheduleBar() {
        //关闭小车帧动画
        if (mAnimationDrawable != null && mAnimationDrawable.isRunning()) {
            mAnimationDrawable.stop();
        }

        int deltaTranslationX = getDeltaTranslationX();
        ObjectAnimator translateAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "translationX", deltaTranslationX, 0);
        translateAnimator.setInterpolator(new AccelerateInterpolator());
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "alpha", 1, 0.3f);
        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mScheduleBarRl, "scaleX", 1, 0.3f);

        AnimatorSet exitAnimatorSet = new AnimatorSet();
        exitAnimatorSet.setDuration(PICK_UP_MOVE_DURATION);
        exitAnimatorSet.playTogether(translateAnimator, alphaAnimator, scaleXAnimator);

        exitAnimatorSet.start();
    }

    @Override
    public void updateDataBetweenRideStatus(int fromRideStatus, int toRideStatus, String driverMobile) {
        if (fromRideStatus == SpecialCarRideStatus.DISPATCH
                && toRideStatus == SpecialCarRideStatus.UN_GET_IN) {
            setupScheduleBarStatus(getString(R.string.depart_customer_hint), false);
            initializePhonePopupWindow(driverMobile);
        } else if (fromRideStatus == SpecialCarRideStatus.UN_GET_IN
                && toRideStatus == SpecialCarRideStatus.DISPATCH) {
            setupScheduleBarStatus(getString(R.string.depart_wait_hint_again), true);
        }
    }

    @Override
    public void startEnterAnimatorForDriverInfoAndScheduleBar(boolean runNextAnimator) {
        startEnterAnimatorForDriverInfo(runNextAnimator);
    }

    @Override
    public void updateTimeAndDistanceValue(String runTime, String runDistance) {
        if (!TextUtils.isEmpty(runTime)) {
            mScheduleTimeTv.setText(runTime);
        }

        if (!TextUtils.isEmpty(runDistance)) {
            mScheduleDistance.setText(runDistance);
        }
    }

    /**
     * 启动/退出底栏弹出框
     *
     * @param needUpTranslation true,需要向上弹出,false,需要向下退出弹框
     */
    @Override
    public void startTimeDistanceInfoBarAnimator(boolean needUpTranslation) {

        int height = mScheduleTimeDistanceBar.getHeight();

        PropertyValuesHolder translationValuesHolder;
        PropertyValuesHolder alphaValuesHolder;
        ObjectAnimator translationAnimator;
        //上移
        if (needUpTranslation) {
            translationValuesHolder = PropertyValuesHolder.ofFloat("translationY", 0, (-1) * height);
            alphaValuesHolder = PropertyValuesHolder.ofFloat("alpha", 0f, 1f);
            translationAnimator = ObjectAnimator.ofPropertyValuesHolder(
                    mScheduleTimeDistanceBar,
                    translationValuesHolder,
                    alphaValuesHolder
            );
            translationAnimator.setInterpolator(new DecelerateInterpolator());
        }
        //下移
        else {
            translationValuesHolder = PropertyValuesHolder.ofFloat("translationY", (-1) * height, 0);
            alphaValuesHolder = PropertyValuesHolder.ofFloat("alpha", 1f, 0f);
            translationAnimator =
                    ObjectAnimator.ofPropertyValuesHolder(
                            mScheduleTimeDistanceBar,
                            translationValuesHolder,
                            alphaValuesHolder
                    );
            translationAnimator.setInterpolator(new AccelerateInterpolator());
        }

        translationAnimator.setDuration(300);
        translationAnimator.start();
    }

    /**
     * 结束对话框     跳到评价
     *
     * @param bizOrderResponse
     */
    @Override
    public void showArrivalDialog(final BizOrderResponse bizOrderResponse) {
        //弹出行程结束对话框  跳到 评论页面
        ZMDialog zmDialog = new ZMDialog.Builder(mActivity)
                .setTitle("本次行程已结束")
                .setMessage("行驶" + bizOrderResponse.getRunDistance() + "公里    用时" + bizOrderResponse.getRunTime())
                .setPositiveMessage(getString(R.string.confirm))
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        if (bizOrderResponse != null) {
                            AppraisalDriverInfo driverInfo = new AppraisalDriverInfo();
                            OfficialCarScheduleActivity activity = (OfficialCarScheduleActivity) getActivity();
                            driverInfo.setOrderId(DiskCacheUtils.getInstance(activity).getOfficialCarOrderId())
                                    .setDriverName(bizOrderResponse.getDriverName())
                                    .setHistoryScore((int) bizOrderResponse.getDriverJudgePoint())
                                    .setPlateNumber(bizOrderResponse.getVehicleNo());
                            activity.navigator.navigateToAppraisal(activity, driverInfo);
                        }
                        getActivity().finish();
                    }
                })
                .show();

    }

    @Override
    public void routeResultFailure() {

    }


    @Override
    public void closeCommentOnCompleted() {
        //   CommentDriverPopupWindowHelper.getInstance(mOfficialCarScheduleMapPresenter, getContext()).closePopupWindow();
    }

    @Override
    public void renderCommentOnError(String msg) {
        // CommentDriverPopupWindowHelper.getInstance(mOfficialCarScheduleMapPresenter, getContext()).onError();
    }

    @Override
    public void renderCommentOnSuccess() {
//        CommentDriverPopupWindowHelper.getInstance(mOfficialCarScheduleMapPresenter, getContext()).onCommentSuccess(mActivity);
    }


    @Override
    protected void initializeInjector() {
        DaggerOfficialCarComponent
                .builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(mActivity))
                .build()
                .inject(this);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_official_car_schedule;
    }

    @Override
    protected void setupToolBar() {
        if (mActivity instanceof OfficialCarScheduleActivity) {
            OfficialCarScheduleActivity scheduleActivity = (OfficialCarScheduleActivity) mActivity;
            scheduleActivity.setToolbar(
                    getString(R.string.route_detail_no_charter),
                    getString(R.string.special_car_operation_cancel_trip));
        }
    }


}
